package com.takanafu.haru.code{
	import com.takanafu.haru.core.GlobalManager;
	
	public class CodeSymbol extends CodeBase{
		private var name:String;
		private static var table:Object = new Object();
		
		public function CodeSymbol(s:String){
			this.name = s;
			table[s] = this;
		}
		
		public static function intern(s:String):CodeSymbol{
			if(table.hasOwnProperty(s) == true){
				return table[s] as CodeSymbol;
			}
			return new CodeSymbol(s);
		}
		override public function run():CodeBase{
			var c:CodeBase = GlobalManager.getSymbolValue(this);
			
			if(c == null){
				throw new Error("シンボル" + name + "は定義されていません。");
			}
			return c;
		}
		
		override public function toString():String{
			return name;
		}
	}
}